#include <iostream>
#include <sys/time.h>

#include "Utils.h"
#include "Perfs.h"


using namespace std;

double	Perfs::my_gettimeofday()
{
	struct timeval tmp_time;
	gettimeofday(&tmp_time, NULL);

	return tmp_time.tv_sec + (tmp_time.tv_usec * 1.0e-6L);
}

double Perfs::dotprodFLOP(unsigned int size)
{
	return 2 * size - 1.;
}

double Perfs::mvFLOP(unsigned int rows, unsigned int columns)
{
	return rows * dotprodFLOP(columns);
}

double Perfs::axpyFLOP(unsigned int size)
{
	return size * 2;
}

double Perfs::mmFLOP(unsigned int size)
{
	return  dotprodFLOP(size) * size * size;
}

double Perfs::mvPerf(unsigned int rows, unsigned int columns, double time)
{
	return mvFLOP(rows,columns) / time * 1.0e-9;
}

double Perfs::mmPerf(unsigned int size, double time)
{
	if (time == 0.0)
		return 0.0;

	return mmFLOP(size) / time * 1.0e-9;
}


void Perfs::Display(string s_method, double time, double flops)
{
	cout << "\\_o< Time " << s_method << " : " << time << " s" << endl;
	cout << "\\_o< Perf " << s_method << " : " << flops << " GFlops" << endl << endl;
}
